<html>
<head>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>Omipay Merchant</title>
    <link rel="stylesheet" href="plugins/sweetAlert/sweetalert.css">
    <link rel="stylesheet" href="plugins/loading-mobile/css/loading.css">
    <script src="plugins/jquery-1.11.3.js"></script>
    <script src="plugins/sweetAlert/sweetalert.min.js"></script>
    <script src="plugins/loading-mobile/js/loading.js"></script>
    <script>
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        $(document).ready(function () {
            loading.show();
            var code = getQueryString("code");
            if (code) {
                $.ajax({
                    type: "post",
                    url: "http://47.91.42.63/API/system/wechat_login",
                    contentType: 'application/json;charset=utf-8',
                    data: JSON.stringify({code: code, language: 'EN', appid: '44C02BF6-1D02-4B18-8613-26F26405CAE4'}),
                    success: function (data) {
                        loading.hidden();
                        if (data.return_code == "SUCCESS") {
                            sessionStorage['merchant'] = JSON.stringify(data);
                        }
                        location.href = "main.html";
                    },
                    error: function (err) {
                        if($("#myLoading")){
                            loading.hidden();
                        }
                        var data = JSON.parse(err.responseText);
                        if (data.openid) {
                            localStorage['openid'] = data.openid;
                            location.href = "login.html";
                        }
                    }
                })
            }
        });
    </script>
</head>
<body>
</body>

</html>